#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    void rotate(vector<int>& nums, int k)
    {
        int n = k % nums.size();
        reverse(nums.begin(), nums.end());
        reverse(nums.begin(), nums.begin() + n);
        reverse(nums.begin() + n, nums.end());

    }
};

class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals)
    {
        sort(intervals.begin(), intervals.end());
        vector<vector<int>> ret;
        int left = intervals[0][0], right = intervals[0][1];
        //ret.push_back({left,right});
        int n = intervals.size();
        for (int i = 1; i < n; i++)
        {
            int a = intervals[i][0], b = intervals[i][1];
            if (right >= a)
            {
                right = max(right, b);
            }
            else
            {
                ret.push_back({ left,right });
                left = a;
                right = b;
            }

        }
        ret.push_back({ left,right });
        return ret;

    }
};

class Solution {
public:
    int maxSubArray(vector<int>& nums)
    {
        int dp[100000] = { 0 };
        dp[0] = nums[0];
        int n = nums.size();
        int ret = dp[0];
        for (int i = 1; i < n; i++)
        {
            dp[i] = max(nums[i], dp[i - 1] + nums[i]);
            ret = max(ret, dp[i]);
        }

        return ret;
    }
};